//
// Created by xili on 2024/7/31 16:52.
// Go big or go home.
//
#include <vector>
#include <valarray>

using namespace std;

class Solution {
public:
    vector<int> leftRightDifference(vector<int> &nums) {
        int n = nums.size();
        vector<int> leftsum(n, 0);
        vector<int> rightsum(n, 0);
        vector<int> ans(n, 0);
        int sum = 0;
        for (int i = 0; i < n - 1; i++) {
            sum += nums[i];
            leftsum[i + 1] = sum;
        }
        sum += nums[n - 1];
        for (int i = 0; i < n - 1; i++) {
            sum -= nums[i];
            rightsum[i] = sum;
        }
        for (int i = 0; i < n; i++) {
            ans[i] = abs(leftsum[i] - rightsum[i]);
        }
        return ans;
    }
};